package com.ext.aic.apis.user;

import android.content.Context;

import androidx.lifecycle.LifecycleOwner;

import com.ext.aic.apis.ApiDefine;
import com.ext.aic.apis.ApiPaths;
import com.ext.aic.apis.RequestResponse;
import com.ext.aic.beans.params.RefreshTokenParams;
import com.ext.aic.beans.response.RefreshTokenResponse;
import com.eyinfo.android_pure_utils.utils.JsonUtils;
import com.hjq.http.EasyHttp;
import com.hjq.http.body.JsonRequestBody;
import com.hjq.http.config.IRequestApi;

public class RefreshTokenRequest {

    protected void onRefreshTokenCall(RefreshTokenResponse response) {

    }

    protected void onRefreshTokenEnd() {

    }

    public void request(Context context, LifecycleOwner lifecycleOwner, RefreshTokenParams params) {
        EasyHttp.post(lifecycleOwner)
                .api(new ApiDefine(ApiPaths.refreshToken))
                .body(new JsonRequestBody(JsonUtils.toJson(params)))
                .request(new RequestResponse<RefreshTokenResponse>(context, false) {
                    @Override
                    protected void onSuccess(RefreshTokenResponse response) {
                        if (response == null) {
                            return;
                        }
                        onRefreshTokenCall(response);
                    }

                    @Override
                    public void onHttpEnd(IRequestApi api) {
                        onRefreshTokenEnd();
                    }
                });

    }
}
